<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>实验室助理工作管理系统</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
    <meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
    <meta name="author" content="yinqi">
    <link rel="stylesheet" th:href="@{/Light-Year-Admin/css/bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{/Light-Year-Admin/css/materialdesignicons.min.css}">
    <link rel="stylesheet" th:href="@{/Light-Year-Admin/css/style.min.css}">
    <!--对话框-->
    <link rel="stylesheet" th:href="@{/Light-Year-Admin/js/jconfirm/jquery-confirm.min.css}">
</head>
<body>
<!--页面主要内容-->
<div class="row">
    <ul id="tb_teacher">
    </ul>
</div>

<!-- 模态框 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">填写报名信息</h4>
            </div>
            <div class="modal-body">

                <!--页面主要内容-->
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body">
                                <form action=""  class="row" id="userForm" name="myform">
                                    <input id="planId" type="text" hidden>
                                    <input id="status" type="text" value="1" hidden>
                                    <div class="form-group col-md-12">
                                        <label for="workName">岗位名称</label>
                                        <input type="text" class="form-control" id="workName" name="workName" value="" placeholder="" required/>
                                    </div>
                                    <div class="form-group col-md-12">
                                        <label for="stuId">学号</label>
                                        <input type="text" class="form-control" id="stuId" name="stuId" value="" placeholder="" required/>
                                    </div>
                                    <div class="form-group col-md-12">
                                        <label for="stuName">姓名</label>
                                        <input type="text" class="form-control" id="stuName" name="stuName" value="" placeholder="" required/>
                                    </div><div class="form-group col-md-12">
                                    <label for="skill">技能描述</label>
                                    <input type="text" class="form-control" id="skill" name="skill" value="" placeholder="" required/>
                                </div>
                                </form>

                            </div>
                        </div>
                    </div>
                </div>
                <!--End 页面主要内容-->
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="modify()">提交</button>
            </div>
        </div>
    </div>
</div>
<!--End 页面主要内容-->


<script type="text/javascript" th:src="@{/js/jquery-3.6.0.min.js}"></script>
<script type="text/javascript" th:src="@{/Light-Year-Admin/js/bootstrap.min.js}"></script>
<script type="text/javascript" th:src="@{/Light-Year-Admin/js/perfect-scrollbar.min.js}"></script>
<script type="text/javascript" th:src="@{/Light-Year-Admin/js/main.min.js}"></script>
<!--消息提示-->
<script th:src="@{/Light-Year-Admin/js/bootstrap-notify.min.js}"></script>
<script type="text/javascript" th:src="@{/Light-Year-Admin/js/lightyear.js}"></script>
<!--对话框-->
<script th:src="@{/Light-Year-Admin/js/jconfirm/jquery-confirm.min.js}"></script>

<script type="text/javascript">
    var userId = "";
    var userName = "";
    var perms = "";
    $(function () {
        // 查询所有数据
        getLab();

        // 获取session（获取登录者的id）
        $.ajax({
            "url" : "getUserSession",
            "method" : "POST",
            "cache" : false,
            "async" : false,
            success: function (result) {
                if (result.code == 200){
                    userId = result.id;
                    userName = result.name;
                    perms = result.perms;
                    $("#name1").html(perms+"："+userName);
                }
            }
        });
    });

    // 查询所有数据
    function getLab() {
        $.ajax({
                type: "GET",
                url: "/recruitmentPlan/findAll",
                contentType: 'application/json;charset=utf-8', //设置请求头信息
                dataType: "json",
                success: function (result) {
                    let html = "";
                    //遍历结果集result,
                    for(let i = 0;i<result.length;i++){
                        if (result[i].status == 1){
                            // 招聘计划已审核
                            html += '<div class="col-sm-6 col-lg-3" ><div class="card"><div class="card-header bg-primary"><h4>'+result[i].planName+'</h4>'+
                                '<ul class="card-actions"><li><button type="button"><i class="mdi mdi-more"></i></button></li></ul></div><div class="card-body">'+
                                '<p>岗位：'+result[i].wordName+'</p>'+
                                '<p>岗位要求：'+result[i].jobRequirements+'</p>'+
                                '<p>招聘人数：'+result[i].recruitsNumber+'</p>'+
                                '<p>招聘部门：'+result[i].deptName+'</p>'+
                                '<p>开始时间：'+result[i].startTime+'</p>'+
                                '<p>截止时间：'+result[i].endTime+'</p>'+
                                '<p>'+'<a class="btn btn-info btn-sm" role="button" href="javascript:edit(\''+result[i].planId+'\')"><i class="mdi mdi-pencil"></i>报名</a></p>'+
                                '</div></div></div>';
                        }
                    }
                    //将html标签拼接在html中
                    $("#tb_teacher").html(html);
                }
            }
        )
    }

    // 新增
    function modify() {
        //获取模态框数据
        var workName = $("#workName").val();
        var stuId = $("#stuId").val();
        var stuName = $("#stuName").val();
        var skill = $("#skill").val();
        var isInterview = '2'; //是否进入面试(1进入、0没进入、2未审核)

        var param = {workName: workName, stuId: stuId, stuName: stuName, skill: skill,isInterview:isInterview};

        $.ajax({
            url: "/student/add",
            type: "POST",
            contentType: "application/json",
            dataType: "json",
            data: JSON.stringify(param),
            success: function (data) {
                if(data.code == 200 ){
                    reset();
                    $('#myModal').modal('hide');
                    getLab();
                    lightyear.notify('报名成功！', 'success', 1000, 'mdi mdi-emoticon-happy', 'top', 'center');
                }else{
                    alert("失败")
                }
            }
        });
    }

    // 打开修改页面
    function edit(planId) {
        reset()
        console.log()
        $.ajax({
            url: "/recruitmentPlan/findOne/" + planId,
            type: "GET",
            success: function (result) {
                if (result.data) {
                    //向模态框中传值
                    $('#workName').val(result.data.wordName);
                    $('#stuId').val(userId);
                    $('#stuName').val(userName);
                } else {
                    alert(result.data.message);
                }
            }
        });
        $('#myModal').modal('show');
    }

    // 清空模态框
    function reset() {
        $("#workName").val("");
        $("#stuId").val("");
        $("#stuName").val("");
        $("#skill").val("");
    }

</script>

</body>
</html>